import date from "../uni_modules/sky-nutui/components/sky-nutui/packages/utils/date";

export const getDate = () => {
	let now = new Date();
	let year = now.getFullYear(); //获取完整的年份(4位,1970-????)
	let month = now.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	let today = now.getDate(); //获取当前日(1-31)
	let hour = now.getHours(); //获取当前小时数(0-23)
	let minute = now.getMinutes(); //获取当前分钟数(0-59)
	let second = now.getSeconds(); //获取当前秒数(0-59)
	let nowTime = ''
	nowTime = year + '-' + fillZero(month) + '-' + fillZero(today) + ' ' + fillZero(hour) + ':' +
	  fillZero(minute) + ':' + fillZero(second)
	return nowTime

} 

function fillZero (str) {
  var realNum;
  if (str < 10) {
    realNum = '0' + str;
  } else {
    realNum = str;
  }
  return realNum;
}
export const initTimeRadio = ()=> {
	console.log('初始化时间选择器');
	const week = ['日','一','二','三','四','五','六'];
	let today = new Date();
	let start_index = -3;//1表示从第二天开始
	// 初始化最近10天的日期数组
	let dates = [];

	for (let i = start_index; i < start_index+10; i++) {

		// 计算日期差值，向前推算日期
		let diff = new Date(today);
		diff.setDate(today.getDate() + i);
		// if (i===0){
		// 	state.value.tab4value =`${diff.getFullYear()}-${(diff.getMonth() + 1).toString().padStart(2, '0')}-${diff.getDate().toString().padStart(2, '0')}`
		// 	state.value.appointmentTitle ='周'+week[diff.getDay()]+' '+(diff.getMonth() + 1).toString().padStart(2, '0')+'.'+diff.getDate().toString().padStart(2, '0');
		// }

		let dateObj={};
		dateObj.key = `${diff.getFullYear()}-${(diff.getMonth() + 1).toString().padStart(2, '0')}-${diff.getDate().toString().padStart(2, '0')}`;
		// dateObj.xq = '周'+week[diff.getDay()];
		// dateObj.rq = (diff.getMonth() + 1).toString().padStart(2, '0')+'.'+diff.getDate().toString().padStart(2, '0');
		dates.push(dateObj);
	}
	console.log('初始化时间选择器结束');
	return dates;
}
